home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / test.zip / CHKTEST.BAT < prev    next >
DOS Batch File  |  1994-04-14  |  5KB  |  208 lines

  1. @echo off
  2. echo ------------------------------------------------------------
  3. echo Exercise test utility program: test.exe
  4. echo.
  5. echo This test assumes test.exe is newer than test.c;
  6. echo i.e., the timestamp of test.exe is more recent.
  7. echo ------------------------------------------------------------
  8. echo.
  9. if not exist test.exe goto noTest
  10. if not exist test.c goto noTest
  11.  
  12. REM Create/change tmp files/directories
  13.  
  14. attrib +r test.exe > nul
  15. if errorlevel 1 echo attrib errorlevel
  16. if not exist test.dir\nul md test.dir
  17. type nul > zero
  18.  
  19. REM Test #1 *** Compare file lengths - IsSameSize(f1,f2) ***
  20. test ! -S test.c test.exe
  21. if errorlevel 1 echo test1  -OK-    !SameSize(f1,f2)
  22. test -S test.c test.exe
  23. if errorlevel 1 echo test1  *FAIL*    SameSize(f1,f2)
  24.  
  25. REM Test #2
  26. test -S test.c test.c
  27. if errorlevel 1 echo test2  -OK-    SameSize(f1,f2)
  28.  
  29. REM Test #3
  30. test ! -S test.exe unknownfile
  31. if errorlevel 1 echo test3  -OK-    different sizes [or not exist]
  32. test -S test.exe unknownfile
  33. if errorlevel 1 echo test3-FAIL: same file sizes
  34.  
  35. REM Test #4 *** Compare file time stamps - IsNewerThan(f1,f2) ***
  36. test -N zero test.exe
  37. if errorlevel 1 echo test4  -OK-    file1 is newer than file2
  38.  
  39. REM Test #5
  40. test -N test.c test.exe
  41. if errorlevel 1 goto err5
  42. echo test5  -OK-    file1 is NOT newer than file2
  43. goto test6
  44. :err5
  45. echo test5  *FAIL*    file1 is newer than file2
  46.  
  47. REM Test #6
  48. :test6
  49. test -D test.c test.exe
  50. if errorlevel 1 echo test6  *FAIL*    same time stamps
  51. test ! -D zero test.exe
  52. if errorlevel 1 echo test6  -OK-    different time stamps
  53.  
  54. REM Test #7 *** Directory ***
  55. test ! -d test.c
  56. if errorlevel 1 echo test7  -OK-    file is not a directory
  57.  
  58. REM Test #8
  59. test -d test.dir
  60. if errorlevel 1 echo test8  -OK-    tmp is a directory
  61.  
  62. REM Test #9
  63. test -m zero
  64. if errorlevel 1 echo test9  -OK-    file has been modified
  65.  
  66. REM Test #10
  67. test ! -m %COMSPEC%
  68. if errorlevel 1 echo test10 -OK-    file is older than 1 day
  69.  
  70. REM Test #11 *** Zero file length ***
  71. test -z zero
  72. if errorlevel 1 echo test11 -OK-    ZeroLen(f1)
  73. test ! -z zero
  74. if errorlevel 1 echo test11 *FAIL*    !ZeroLen(f1)
  75.  
  76. REM Test #12
  77. test ! -z test.exe
  78. if errorlevel 1 echo test12 -OK-    !ZeroLen(f1)
  79. test -z test.exe
  80. if errorlevel 1 echo test12 *FAIL*    ZeroLen(f1)
  81.  
  82. pause
  83.  
  84. REM Test #13 *** Non-zero file length ***
  85. test ! -s zero
  86. if errorlevel 1 echo Test13 -OK-    ZeroLen(f1)
  87.  
  88. REM Test #14
  89. test -s test.c
  90. if errorlevel 1 echo Test14 -OK-    !ZeroLen(f1)
  91.  
  92. REM TEST #15 *** Executable files ***
  93. test ! -x test.c
  94. if errorlevel 1 echo test15 -OK-    file is not executable
  95.  
  96. REM TEST #16
  97. test -x test.exe
  98. if errorlevel 1 echo test16 -OK-    file is executable
  99. test ! -x test.exe
  100. if errorlevel 1 echo test16 *FAIL*    file is not executable
  101.  
  102. REM TEST #17
  103. test -x %0.bat
  104. if errorlevel 1 echo test17 -OK-    file is executable
  105. test ! -x %0.bat
  106. if errorlevel 1 echo test17 *FAIL*    file is not executable
  107.  
  108. REM Test #18 *** Writable/read-only files ***
  109. test ! -w test.exe
  110. if errorlevel 1 echo test18 -OK-    file is read-only
  111. test -w test.exe
  112. if errorlevel 1 echo test18 *FAIL*    file is writable
  113.  
  114. REM Test #19
  115. test -w test.c
  116. if errorlevel 1 echo test19 -OK-    file is writable
  117. test ! -w test.c
  118. if errorlevel 1 echo test19 *FAIL*    file is read-only
  119.  
  120. REM Test #20 *** Regular file ***
  121. test ! -f nul
  122. if errorlevel 1 echo test20 -OK-    file is a special file
  123. test -f nul
  124. if errorlevel 1 echo test20 *FAIL*    file is a regular file
  125.  
  126. REM Test #21
  127. test -f test.exe
  128. if errorlevel 1 echo test21 -OK-    file is a regular file
  129.  
  130. REM Test #22 *** Block special ***
  131. test -b nul
  132. if errorlevel 1 echo test22 -OK-    file is a block special file
  133.  
  134. REM Test #23
  135. test ! -b test.exe
  136. if errorlevel 1 echo test23 -OK-    file is not a block special file
  137.  
  138. REM Test #24 *** Character special ***
  139. test -c nul
  140. if errorlevel 1 echo test24 -OK-    file is a character special file.
  141.  
  142. REM Test #25
  143. test ! -c test.exe
  144. if errorlevel 1 echo test25 -OK-    file is not a character special file
  145.  
  146. REM Test #26 *** Logical or ***
  147. test -d test.c -o -z zero
  148. if errorlevel 1 goto ok26
  149. echo test26 *FAIL*    !IsAdir(f1) and !ZeroLen(f2)
  150. goto test27
  151. :ok26
  152. echo test26 -OK-    IsAdir(f1) or ZeroLen(f2)
  153.  
  154. REM Test #27
  155. :test27
  156. test -d test.c -o -z test.c
  157. if errorlevel 1 echo test27 *FAIL*    IsAdir(f1) or ZeroLen(f2)
  158. test ! -d test.c -o ! -z test.c
  159. if errorlevel 1 echo test27 -OK-    !IsAdir(f1) and !ZeroLen(f2)
  160.  
  161. REM Test #28 *** Logical AND ***
  162. test -w test.c -a ! -z test.c
  163. if errorlevel 1 echo test28 -OK-    file1 is writable and !ZeroLen(file2)
  164.  
  165. REM Test #29
  166. test -w test.c -a -z zero
  167. if errorlevel 1 goto ok29
  168. echo test29 *FAIL*    ReadOnly(file1) or !ZeroLen(file2)
  169. goto test30
  170. :ok29
  171. echo test29 -OK-    writable(f1) and ZeroLen(f2)
  172.  
  173. REM Test #30
  174. :test30
  175. test -d test.dir -z zero -o -S test.c test.exe
  176. if errorlevel 1 goto ok30
  177. echo test30 *FAIL*    expression false
  178. goto test31
  179. :ok30
  180. echo test30 -OK-    expression true
  181.  
  182. REM Test #31
  183. :test31
  184. test
  185. if errorlevel 1 goto err31
  186. echo test31 -OK-    no arguments
  187. goto done
  188. :err31
  189. echo test31 *FAIL*    no arguments
  190.  
  191. :done
  192. echo.
  193. echo All tests numbered from 1-31 should appear with OK status!
  194.  
  195. REM *** Clean up new or changed files ***
  196. :clean
  197. attrib -r test.exe > nul
  198. del zero > nul
  199. rd test.dir
  200. goto end
  201.  
  202. :noTest
  203. echo Error: Missing required program(s).  The files 'test.exe' or 'test.c'
  204. echo        must be located in this directory for test to complete.
  205. echo.
  206. echo        DOS attrib command must be in path.
  207. :end
  208.